package edu.neusoft.yuejian_09.model;

import java.util.List;

import edu.neusoft.yuejian_09.bean.Club;
import edu.neusoft.yuejian_09.bean.Video;
import edu.neusoft.yuejian_09.service.ClubActService;
import edu.neusoft.yuejian_09.service.ClubService;
import edu.neusoft.yuejian_09.service.ClubTrainService;
import retrofit2.Call;
import retrofit2.Retrofit;
import retrofit2.converter.gson.GsonConverterFactory;

/**
 * Created by Administrator on 2017/10/10.
 */

public class ClubModel {
    private Retrofit retrofit;
    public ClubModel(){
        retrofit=new Retrofit.Builder()
                .baseUrl("http://10.0.2.2/neu1_yuejian/index.php/Api/")
                .addConverterFactory(GsonConverterFactory.create())
                .build();
    }
    public Call clublist(){
        ClubService clubService=retrofit.create(ClubService.class);
        return  clubService.getAllClub();

    }
    //俱乐部详情

    public Call<Club> getClubinfo(int c_id){
        ClubService clubService = retrofit.create(ClubService.class);
        return clubService.getClubinfo(c_id);
    }
    public Call getClubactivitys(String c_id) {
        ClubActService clubActService = retrofit.create(ClubActService.class);
        return clubActService.getClubActivities(c_id);

    }

    public Call getClubtrains(String c_id) {
        ClubTrainService clubTrainService = retrofit.create(ClubTrainService.class);
        return clubTrainService.getClubTrains(c_id);

    }
   /* public void getClubactivitys(int c_id,final RetorfitListener listener){

        ClubService clubService = retrofit.create(ClubService.class);
        Call call = clubService.getClubactivitys(c_id);
        System.out.print(c_id);
        Callback<List<Activities>> callback = new Callback<List<Activities>>() {
            @Override
            public void onResponse(Call<List<Activities>> call, Response<List<Activities>> response) {
                List<Activities> activityBeen = response.body();
                listener.onSuccess(activityBeen);
            }
            @Override
            public void onFailure(Call<List<Activities>> call, Throwable t) {
                listener.onFail();
            }
        };
        call.enqueue(callback);

    }


    public void getClubcourselist(int c_id,final RetorfitListener listener){

        ClubService clubService = retrofit.create(ClubService.class);
        Call call = clubService.getClubcourselist(c_id);
        System.out.print(c_id);
        Callback<List<Course>> callback = new Callback<List<Course>>() {
            @Override
            public void onResponse(Call<List<Course>> call, Response<List<Course>> response) {
                List<Course> courseBeen = response.body();
                listener.onSuccess(courseBeen);
            }
            @Override
            public void onFailure(Call<List<Course>> call, Throwable t) {
                listener.onFail();
            }
        };
        call.enqueue(callback);

    }


    public void getClubvideolist(int c_id,final RetorfitListener listener){

        ClubService clubService = retrofit.create(ClubService.class);
        Call call = clubService.getClubvideolist(c_id);
        System.out.print(c_id);
        Callback<List<Video>> callback = new Callback<List<Video>>() {
            @Override
            public void onResponse(Call<List<Video>> call, Response<List<Video>> response) {
                List<Video> videoBeen = response.body();
                listener.onSuccess(videoBeen);
            }
            @Override
            public void onFailure(Call<List<Video>> call, Throwable t) {
                listener.onFail();
            }
        };
        call.enqueue(callback);

    }*/

    //搜索J俱乐部
    public Call<List<Club>> searchClub(String c_name){
        ClubService clubService = retrofit.create(ClubService.class);
        return clubService.searchClub(c_name);
    }


    //俱乐部视频
    public Call<List<Video>> getVideos(){
        ClubService clubService = retrofit.create(ClubService.class);
        return clubService.getVideos();
    }

}


